import turtle as t

t.title('自动轨迹绘制')
t.setup(800, 600, 0, 0)
t.pencolor('red')
t.pensize(5)
t.speed(0)
t.hideturtle()
# 数据读取
datals = []
# 数据格式：前进距离,0左转1右转,角度,颜色RGB值
with open('template.txt', 'rt') as file:
    for line in file:
        line = line.replace("\n", "")
        # map是内嵌函数，将第一个参数的功能作用于第二个参数
        datals.append(list(map(eval, line.split(","))))
    file.close()

# 自动绘制
for i in range(len(datals)):
    t.pencolor(datals[i][3], datals[i][4], datals[i][5])
    t.fd(datals[i][0])
    if datals[i][1]:
        t.right(datals[i][2])
    else:
        t.left(datals[i][2])

t.done()
